Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
`loadURL` in Electron has error "window.require is not a function" only this website

NOTE: Electron 17.0.1

I'm so confuse about to use the win.loadURL function in Electron. For main purpose, to create a dark theme for chat application. I want to loadURL in Electron and inject CSS to change to dark theme.

BUT when I use loadURL and then run Electron app. It will show an error "window.require is not a function" and "Uncaught TypeError: Cannot read properties of undefined (reading 'instance')"

here is my code:

// main.js
const { app, BrowserWindow } = require("electron");
const path = require("path");

function createWindow() {
  const win = new BrowserWindow({
    width: 1200,
    height: 800,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

  win.webContents.openDevTools();
  win.loadURL("https://seatalkweb.com/");
}

app.whenReady().then(() => {
  createWindow();

  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow();
    }
  });
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

// preload.js
window.addEventListener("DOMContentLoaded", () => {
  const replaceText = (selector, text) => {
    const element = document.getElementById(selector);
    if (element) element.innerText = text;
  };

  for (const type of ["chrome", "node", "electron"]) {
    replaceText(`${type}-version`, process.versions[type]);
  }
});

and this is an error: enter image description here enter image description here

I do not know why it has an error only this website when open in electron? (no problem if open in chrome) this website is https://seatalkweb.com/ and it fine if I use other URL instead (such as google.com, facebook.com, etc.)

How can I fix it ? and could somebody can explain me about this problem ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Seems weird like a require is called is your page but it's maybe an Electron call du to the LoadUrl... If it's a require problem you may need to activate the Node integration..

const win = new BrowserWindow({
    width: 1200,
    height: 800,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      nodeIntegration: true
    },
  });

If it's not from Electron Node integration, then in may be a problem in your web page script.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!